import request from '@/api/index'
import { defineStore } from 'pinia';
import { LocationQueryValue } from 'vue-router';
export const userStore = defineStore('user', {
  state: () => ({
    user_id:'' as LocationQueryValue | LocationQueryValue[],
    webType:'' as LocationQueryValue | LocationQueryValue[],
    u_openid:'' as LocationQueryValue | LocationQueryValue[],
    room_id:'' as LocationQueryValue | LocationQueryValue[],
    diamond_balance:0 as number, // 钻石
    ticket_num:0 as number, // 礼物券数量
    newStakeType:0 as number, // 押注
    remind:0 as number,
    zsToGiftLoading:false, // 钻石兑换礼物券拦截
    userStakeLoading:false, // 押注加载拦截
  }),
  getters: {
    
  },
  actions: {
    async getWallet() {
      const res = await request.getUserWallet();
      this.setWallet(res.data || {})
    },
    /**
     * 返回值更新用户钱包
     * @param query 
     */
    setWallet(query:any={}) {
      const { diamond_balance=-1 , ticket_num=-1} = query;
      if(diamond_balance> -1)this.diamond_balance = diamond_balance
      if(ticket_num> -1)this.ticket_num = ticket_num
    },
    async userSet(obj:any = {}) {
      const { type = 0,val = '' } = obj
      const res = await request.userSet({
        type,
        val
      })
      const { remind=0, stakeType=1 } = res?.data || {}
      this.newStakeType = stakeType
      this.remind = remind
    }
  },
})